program soft_constraint;

class packet;
    rand bit [3:0] addr;
    rand bit [3:0] data;
    constraint addr_range { soft addr > 6; } 
    constraint data_range { soft data > 6; } 
endclass

initial begin
    packet pkt;
    pkt = new();
    repeat(10) begin
        // 若软约束被满足时，随机化成功
        // 若软约束未被满足，其会被忽略
        pkt.randomize() with { addr < 6; data < 8; }; // inline constraint
        $display("\taddr = %0d, data = %0d", pkt.addr, pkt.data);
    end
end

endprogram;
